const url = require('url');

class ProxyMatch {
    match(req, cache) {
        const pathName = url.parse(req.url).pathname;
        const routePath = pathName.split('/')[1];
        const routeRule = cache.getRouteRule(`/${routePath}`);
        if (routeRule) {
            req.url = req.url.replace(`/${routePath}`, '');
            return routeRule.targets;
        }
        return null;
    }
}

module.exports = new ProxyMatch();